import inspect
import os
from functools import reduce


def _get_current_path():
    """私有函数
    获取当前文件路径(注意路径包含当前文件名)
    :return: str
    """
    try:
        filename = __file__
    except NameError:  # fallback
        filename = inspect.getsourcefile(_get_current_path)
    return os.path.realpath(filename)


# 返回上n级
def _get_dir(n=1):
    """私有函数
    获取上n级的路径
    :param n: n级路径
    :return: 上n级的路径
    """
    cm_path = _get_current_path()
    return reduce(lambda x, f: f(x), [os.path.dirname] * n, cm_path)


def get_root_path():
    """获取根路径
    :return: str
    """
    return _get_dir(n=1)
